#!/usr/bin/env python
# -*- coding:utf-8 -*-
# import redis
import sys
from rediscluster import StrictRedisCluster

# DB主键序列（Hash） Key：#hash:db.sequence

# r = redis.Redis(host='218.24.72.58', port=7000,db=0)
# r.set('name', 'zhangsan')   #添加
# print (r.get('name'))   #获取

# 192.168.3.1【redis-master端】，
# 192.168.4.12【redis-master端】，
# 192.168.5.10【redis-master端】.   端口：7000
# 218.24.72.58


def redis_cluster():
    redis_nodes =  [{'host': '192.168.3.1','port':7000},
                    {'host': '192.168.4.12', 'port': 7000},
                    {'host': '192.168.5.10', 'port': 7000},
                    ]
    try:
        print(111)
        redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
        print(222)
    except Exception as e:
        print("Connect Error!")
        sys.exit(1)

    redisconn.set('name','admin')
    redisconn.set('age',18)
    print("name is: ", redisconn.get('name'))
    print("age  is: ", redisconn.get('age'))


redis_cluster()


# import redis
# from rediscluster import StrictRedisCluster
# import os, time, sys
#
# serverip = "127.0.0.1"
# startup_nodes = [{'host': '192.168.3.1','port':7000},
#                  {'host': '192.168.4.12', 'port': 7000},
#                  {'host': '192.168.5.10', 'port': 7000},]
#
# def connRedisCluster():
#     rc = StrictRedisCluster(startup_nodes=startup_nodes)
#     return rc
#
# def public_article(conn, article, user, title, link):
#     conn.hmset(article, {'title':title, 'publicer':user, 'link':link})
#
# if __name__=='__main__':
#     print(startup_nodes)
#     rc = connRedisCluster()
#     public_article(rc, 'chinese_history', 'yangsq', 'war', 'http://goon')
#     print(rc.hgetall('chinese_history'))
